package org.example.likou150.tree;

//  https://leetcode.cn/problems/path-sum/?envType=study-plan-v2&envId=top-interview-150
public class HasPathSum {

    /**
    * 叶子节点：下面没节点了
    * */
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if(root==null){
            return false;
        }

        targetSum = targetSum-root.val;
        if(root.left==null && root.right==null){
            return targetSum == 0;
        }
        return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
    }





      public class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode() {}
     TreeNode(int val) { this.val = val; }
     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
 }
}
